<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['diy']=$this->plugin_setting('diy');
if($_RQ['op']=='main'){
	
	exi($return);
}
/*******op*******/
if($_RQ['op']=='list'){
	//查询进入该页面的客户所有订单
	$params=array('user_id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']);
		if(isset($_RQ['status']) && $_RQ['status'] != 10){
		$params['status']=intval($_RQ['status']);
		$return['status']=$_RQ['status'];
	}
	$order_list=pdo_getall('jy_cmsdecorate_order',$params);
	if($order_list){
		foreach($order_list as &$item){
			$member=pdo_get('core_members',array('id'=>$item['user_id'],'uniacid'=>$_SESSION['uniacid']));
			$company=pdo_get('jy_cmsdecorate_company',array('id'=>$item['cid'],'uniacid'=>$_SESSION['uniacid']));
			$item['user_name']=$member['realname'];
			$item['user_mobile']=$member['mobile'];
			$item['company_title']=$company['title'];
			$item['company_image']=$company['image'];
			$item['createtime']=date('Y-m-d H:i:s', $item['createtime']);			
		}
	}
	$return['order_list']=$order_list;
	exi($return);
}
//订单详情
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
	exi('订单不存在，请重新选择','error');
	}
	$order=pdo_get('jy_cmsdecorate_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//用户信息
	$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['user_id']));
	//公司信息
	$company=pdo_get('jy_cmsdecorate_company',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['cid']));	
	$stylister=pdo_get('jy_cmsdecorate_stylist',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['sid']));	
	//print_r($stylister);exit;
	$order['createtime']=date('Y-m-d H:i:s', $order['createtime']);	
	$return['order']=$order;
	$return['member']=$member;
	$return['company']=$company;
	$return['stylister']=$stylister;
	exi($return);
}
if($_RQ['op']=='del'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	pdo_delete('jy_cmsdecorate_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('删除订单成功');
}
/*if($_RQ['op']=='pay'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	$order=pdo_get('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$title=pdo_getcolumn('jy_gohome_serve',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['serve_id']),'title');
	$params['fee']=$order['money'];
	$params['title']='预定'.$title.'订单';
	$params['id']=$_RQ['id'];
	$params['plugin']='jy_gohome';
	$params['back_url']='jy_gohome/order/payresult';
	cfc('core')->pay($params);
}
if($_RQ['op']=='payresult'){
	$payresult=$_SESSION['payresult'];unset($_SESSION['payresult']);
	if(!$payresult){
		exi('支付失败，未收到支付结果！','error','list');
	}
	if($payresult['status']!=1){
		exi('支付失败！','error','list');
	}
	$order=pdo_get('jy_gohome_order',array('id'=>$payresult['id'],'uniacid'=>$_SESSION['uniacid']));
	if(!$order){
		exi('支付失败！指定订单不存在！','error');
	}
	if($order['money']!=$payresult['fee']){
		exi('支付失败！订单金额不匹配！','error');
	}
	pdo_update('jy_gohome_order',array('status'=>1,'pay'=>$payresult['fee']),array('id'=>$order['id']));
	exi('支付成功','success','jy_gohome/order/list/status=1');
}
*/